<template>
	<my-header :title="getEAFlag()" :hasTitle="true" :hasBack="true" :goBack="goBack" :IDGModel="true" :IDGInputSelector="['#addressMobile','#addressUserName','#addressHouseNumber']">
		<!--:IDGModel="true" IDGInputSelector="#addressMobile"-->
		<slot name="zx">
			<div class="aui-pull-right text-del" style="padding-right: 0.8rem;" id="save" @click.stop="onSub">保存</div>
		</slot>
	</my-header>
	<!--<div ref="nav_root" class="nav_root">
		<div style="width: 100%;z-index: 10;" ref="transformBox">
			<div class="headerRight" ref="nav">
				<div class="delivery" ref="back" @click="goBack">
					<i class="symbol1"></i>
					<i class="symbol2"></i>
				</div>
				<div class="detail">{{getEAFlag()}}</div>
				<div class="aui-pull-right text-del" style="position: absolute;top:1px; right:.8rem;" id="save" @click.stop="onSub">保存</div>
			</div>
		</div>
	</div>-->
</template>

<script>
	

import {mapMutations,mapGetters,mapActions} from 'vuex';
import {Toast} from '../../../utils/toast'
import MyHeader from "../../header";

	export default {
	  	name: 'hello',
	  	data () {
	    	return {
				msg: '这是新增地址页面',
	            page: "confirmgoodsinfo",
	            componentName: "confirmgoodsinfoitem",
	            dataList: [],
	            addFlag:false
			}
		},
		computed: {
			...mapGetters([
			
			]),
			...mapGetters('zx',[
				"getaddFlag",'getNowAddress'
			]),
		},
		components: {
	        "my-header":MyHeader
	    },
	    methods: {
	    	...mapActions('zx',[
        		"setAddressInfo"
        	]),
        	...mapMutations('zx',[
				"setNowAddressMutation"
			]),
	        getData() {
				console.log(123456);
	        },
	        getEAFlag(){
	        	this.addFlag = this.$store.getters['zx/getaddFlag'];
	        	console.log(this.addFlag,666);
	        	if(this.addFlag){
	        		return '新增地址';
	        	}else{
	        		return '编辑地址';
	        	}
			},
	        goBack(){
	        	if(this.$route.query.toFrom != undefined){
	        		this.$router.push('chooseAddress');
	        	}else if(this.$route.query.id != undefined){
	        		window.history.back();
	        	}else{
	        		this.$router.push('address');
	        	}
	        	
//	        	window.history.back();
				
	        },
	        showMessage(msg) {
	            Toast({
	                message: msg,
	                duration: 1000,
	                type:'fail'
	            });
	        },
	        //判断vuex中的当前地址是否被刷新没了，如果没了就将local的地址存入vuex
	        checkNowAddress(){
	        	var obj = this.$store.getters['zx/getNowAddress'];
	        	console.log(obj,obj.hasOwnProperty('city'),'dizhidizhidizhi55555');
	        	if(!obj.hasOwnProperty('city')){
	        		console.log(localStorage.getItem('userAddressNow'),'jinijinijijnjijnjijn777777')
					var obj2 = JSON.parse(localStorage.getItem('userAddressNow'));
	        		this.setNowAddressMutation(obj2);
	        	}
	        },
			onSub(){
				var params = {};
				params = this.$store.getters['zx/getNowAddress'];
				console.log("asfgiashfiashfasifa**************",params)
				if(!params.province || !params.city || !params.region ) {
	                this.showMessage('请输入收货地址')
	                return
	            }
//	            if(!params.address) {
//	                this.showMessage('请填写详细地址')
//	                return
//	            }
	            if(!params.receivername) {
	                this.showMessage('请填写收货人姓名')
	                return
	            }
	            if(!params.phone) {
	                this.showMessage('请填写联系号码')
	                return
	            } else {
	                let reg = new RegExp(/^0?(13[0-9]|15[012356789]|17[013678]|18[0-9]|14[57])[0-9]{8}$/)
	                if(!reg.test(parseInt(params.phone))){
	                    this.showMessage('请填写正确的手机号')
	                    return
	                }
	            }
	            if(!params.label) {
	                this.showMessage('请选择地址标签')
	                return
	            }
				
				if(this.addFlag){
					if(this.$route.query.toFrom){
						params.type = 'ADD';
						this.setAddressInfo(params);
		        		this.$router.push('chooseAddress');
		        	}else{
		        		params.type = 'ADD';
						this.setAddressInfo(params);
						let id = this.$route.query.id;
						if(id){
							this.$router.push({path:'address',query:{id:2}});
						}else{
							this.$router.push('address');
						}
		        	}
//					this.$router.push('address');
				}else{
					params.type = 'UPDATE';
					params.showToast = true;
					this.setAddressInfo(params);
//					this.$router.push('address');
					let id = this.$route.query.id;
					if(id){
						this.$router.push({path:'address',query:{id:2}});
					}else{
						this.$router.push('address');
					}
				}
				
			}
	    },
		created () {
//			this.getData();
			this.checkNowAddress();
			this.getEAFlag()
		},
		mounted () {
			
		},
		updated() {
	
		}
	}
	
</script>

<!-- Add "scoped" attribute to limit CSS to this component only -->
<style scoped>
	.box {
		/* display: flex; */
	}
	.style-components {
		display: flex;
		flex-flow: column nowrap;
	}
	.container {
		width: 800px;
		height: 300px;
		border: 1px solid red;

	}
	.nav_root {
		width: 100%;
		overflow: hidden;
	}
	.detail {
		background: transparent;
		min-height: 2.25rem;
		position: absolute;
		margin: 0;
		text-align: left;
		white-space: nowrap;
		left: 3rem;
		width: auto;
		/* overflow: hidden; */
		text-overflow: ellipsis;
		z-index: 2;
		font-weight: 100;
		font-size: 1.1rem;
		top: 1px;
		right: 3rem;
		font-weight: 500;

	}
  .burgers0 {
    transform: translateX(-0.25rem) rotate(-45deg) scaleX(.5);
    /* width: .5rem; */
    margin: 10px 0 2px 0;
  }

  .burgers1 {
    margin: 2px 0 2px 1px;
  }

  .burgers2 {
    transform: translateX(-0.25rem) rotate(45deg) scaleX(.5);
    /* width: .5rem; */
    margin: 2px 1px 2px 0;
  }

  .headerRight {
    width: 100%;
    min-height: 2.25rem;
    font-size: 0.9rem;
    text-align: center;
    display: flex;
	align-items:center;
	justify-content: space-between;
    transition: transform 0.5s ease-out 0.1s;
    transform: translateX(0px);
    border: none;
    background-size: 100% 1px;
    background-repeat: no-repeat;
    background-position: bottom;
    background-image: linear-gradient(0, #eaeaea, #eaeaea 50%, transparent 50%);
    background-image: -webkit-linear-gradient(90deg, #eaeaea, #eaeaea 50%, transparent 50%);
    background: #ffffff;
    height: 3rem;
    line-height: 3rem;
    border-bottom: 1px solid #eaeaea;
    color: #444444;
  }

  .aui-bar-light {
    color: #444444;
    font-weight: bold;
  }

  .burger {
    padding: 0.4rem 0.6rem;
    cursor: pointer;
    margin-left: 0.4rem;
    margin-top: -2px;
    position: absolute;
    top: 0.5rem;
    left: 0;
    transition: all .2s ease-out 0.1s;
  }

  .delivery {
    padding: 0.4rem 1rem 0.4rem 0.6rem;
    cursor: pointer;
    margin-left: 0.4rem;
    margin-top: -2px;
    position: absolute;
    top: 0.5rem;
    left: 0;
    will-change: transform;
    transition: all .2s ease-out 0.1s;
  }

  .delivery > i {
    display: block;
    height: 2px;
    width: .8rem;
    margin: .4rem 0;
    opacity: 0.8;
    background: #000;
    will-change: transform;
    transition: transform 0.2s ease-out;
  }

  .symbol1 {
    transform: rotate(-45deg);
    width: .5rem;
  }

  .symbol2 {
    transform: rotate(45deg);
    width: .5rem;
  }

  .brandLogo {
    left: 3rem;
    right: 3rem;
    min-height: 2.25rem;
    position: absolute;
    margin: 0;
    text-align: center;
    white-space: nowrap;
    width: auto;
    z-index: 2;
    font-weight: 500 !important;
    font-size: 1.1rem;
    margin-top: 0.65rem;
    top: 1px;
  }

  .brandLogo img {
    max-height: 1.6rem;
  }

  .rightIcon {
    position: absolute;
    top: 0.5rem;
    right: 0.75rem;
    font-weight: 100;
    line-height: 1rem;
  }

  .shoppingCart {
    display: inline-block;
    height: 2rem;
    width: 2rem;
    vertical-align: top;
    text-align: center;
    position: relative;
  }

  .njCart {
    font-size: 1.4rem;
    display: inline-block;
    text-align: center;
    position: relative;
    color: #444444;
    opacity: 0.7;
    width: 2rem;
    height: 2rem;
    left: -1px;
    top: 0.3rem;
    text-indent: 0;
    line-height: 1;
  }

  .auiBadge {
    font-weight: bold;
    display: inline-block;
    width: auto;
    text-align: center;
    min-width: 0.8rem;
    height: 0.8rem;
    line-height: 0.8rem;
    padding: 0 0.2rem;
    font-size: 0.6rem;
    color: #ffffff;
    background-color: #ff2600;
    border-radius: 0.4rem;
    position: absolute;
    top: 0.2rem;
    left: 60%;
    z-index: 99;
  }

  .njCart::before {
    content: "\e6e4"
  }
</style>
